<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/mytemplate.xhtml">

    <ui:define name="metadata">
    </ui:define>
    <ui:define name="content">
        <h:form id="connectionForm">
            <p:panelGrid columns="3">
                <f:facet name="header">
                    Selecting connected and connecting net elements
                </f:facet>
                <p:column>
                    <p:dataTable var="equip" value="#{equipmentConnectionService.equipmentsDM}" 
                                 selection="#{equipmentConnectionService.leftSelectedEquipment}"
                                 paginator="true" rows="10" 
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
                        <f:facet name="header">
                        Source Equipment
                        </f:facet>    
                        <p:column selectionMode="single" />
                        <p:column sortBy="#{equip.name}" headerText="Name">
                            <h:outputText value="#{equip.name}"/>
                        </p:column>
                        <p:column sortBy="#{equip.type}" headerText="Type">
                            <h:outputText value="#{equip.type}"/>
                        </p:column>
                        <p:column sortBy="#{equip.address}" headerText="Address">
                            <h:outputText value="#{equip.address}"/>
                        </p:column>
                        <p:column sortBy="#{equip.numOfFreePorts}" headerText="Free Ports">
                            <h:outputText value="#{equip.numOfFreePorts}"/>
                        </p:column>                         
                    </p:dataTable>
                </p:column>
                <p:column>
                    <p:dataTable var="cab" value="#{equipmentConnectionService.cablesDM}" 
                                 selection="#{equipmentConnectionService.selectedCable}"
                                 paginator="true" rows="10" 
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
                        <f:facet name="header">
                        Connecting Cable
                        </f:facet>
                        <p:column selectionMode="single"/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
                        <p:column sortBy="#{cab.name}" headerText="Name">
                            <h:outputText value="#{cab.name}"/>
                        </p:column>
                        <p:column sortBy="#{cab.type}" headerText="Type">
                            <h:outputText value="#{cab.type}"/>
                        </p:column>
                        <p:column sortBy="#{cab.numOfFreeWires}" headerText="Free wires">
                            <h:outputText value="#{cab.numOfFreeWires}"/>
                        </p:column>
                    </p:dataTable>   
                </p:column>
                <p:column>
                    <p:dataTable var="equip" value="#{equipmentConnectionService.equipmentsDM}" 
                                 selection="#{equipmentConnectionService.rightSelectedEquipment}"
                                 paginator="true" rows="10" 
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                 lazy="true">
                        <f:facet name="header">
                        Destination Equipment
                        </f:facet>
                        <p:column selectionMode="single" />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
                        <p:column sortBy="#{equip.name}" headerText="Name">
                            <h:outputText value="#{equip.name}"/>
                        </p:column>
                        <p:column sortBy="#{equip.type}" headerText="Type">
                            <h:outputText value="#{equip.type}"/>
                        </p:column>
                        <p:column sortBy="#{equip.address}" headerText="Address">
                            <h:outputText value="#{equip.address}"/>
                        </p:column>
                        <p:column sortBy="#{equip.numOfFreePorts}" headerText="Free Ports">
                            <h:outputText value="#{equip.numOfFreePorts}"/>
                        </p:column>
                    </p:dataTable>
                </p:column>
                <f:facet name="footer">
                       <p:commandButton value="Select Ports"
                                        update="PortSelection" 
                                        actionListener="#{equipmentConnectionService.initializePorts()}"
                                        oncomplete="portDialog.show()"/>  
                </f:facet>
            </p:panelGrid>          
             <p:dialog header="Select Ports"
                  widgetVar="portDialog">
                <h:panelGrid id="PortSelection" columns="2" >
                    <f:facet name="header">
                        Selected Equipments
                    </f:facet>
                    <p:column>
                        <p:dataTable var="lp" value="#{equipmentConnectionService.leftPortsDM}" 
                                     selection="#{equipmentConnectionService.leftSelectedPort}"
                                     paginator="true" rows="5" 
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
                            <f:facet name="header">
                                #{equipmentConnectionService.leftSelectedEquipment.name}
                            </f:facet>    
                            <p:column selectionMode="single" disabledSelection="#{lp.occupied}"/>
                            <p:column sortBy="#{lp.name}" headerText="Name">
                                <h:outputText value="#{lp.name}"/>
                            </p:column>
                        </p:dataTable>
                    </p:column>
                    <p:column>
                        <p:dataTable var="rp" value="#{equipmentConnectionService.rightPortsDM}" 
                                     selection="#{equipmentConnectionService.rightSelectedPort}"
                                     paginator="true" rows="5" 
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
                            <f:facet name="header">
                                #{equipmentConnectionService.rightSelectedEquipment.name}
                            </f:facet>    
                            <p:column selectionMode="single" disabledSelection="#{rp.occupied}"/>
                            <p:column sortBy="#{rp.name}" headerText="Name">
                                <h:outputText value="#{rp.name}"/>
                            </p:column>
                        </p:dataTable>
                    </p:column>
                    <f:facet name="footer">
                        <p:commandButton value="Connect Ports"
                                        actionListener="#{equipmentConnectionService.connect()}"
                                        oncomplete="portDialog.hide()"/>
                    </f:facet>
                </h:panelGrid>                       
            </p:dialog>
                   
            
            
            
        </h:form>
        
        
       
    </ui:define>
</ui:composition>

